/**
 * Panel.as
 * Keith Peters
 * version 0.9.7
 *
 * A rectangular panel. Can be used as a container for other components.
 *
 * Copyright (c) 2010 Keith Peters
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.feng.components
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.utils.Dictionary;

	public class FPanel
	{
		private static var panelDic:Dictionary = new Dictionary();

		public static function make(panelMc:MovieClip):FPanel
		{
			if (panelDic[panelMc] == null)
			{
				panelDic[panelMc] = new FPanel(panelMc);
			}
			return panelDic[panelMc];
		}

		public static function getLabel(panelMc:MovieClip):FPanel
		{
			return make(panelMc);
		}

		protected var _panelMc:MovieClip;

		protected var _mask:Sprite;

		/**
		 * Container for content added to this panel. This is masked, so best to add children to content, rather than directly to the panel.
		 */
		public var content:Sprite;

		/**
		 * Constructor
		 * @param parent The parent DisplayObjectContainer on which to add this Panel.
		 * @param xpos The x position to place this component.
		 * @param ypos The y position to place this component.
		 */
		public function FPanel(panelMc:MovieClip)
		{
			_panelMc = panelMc;

			init();
		}

		/**
		 * Initializes the component.
		 */
		protected function init():void
		{
			content = _panelMc.content;

			_mask = new Sprite();
			_mask.graphics.clear();
			_mask.graphics.beginFill(0xff0000);
			_mask.graphics.drawRect(0,0,content.width,content.height);
			_mask.graphics.endFill();
			_mask.mouseEnabled = false;

			_panelMc.addChild(_mask);

			content.mask = _mask;
		}
	}
}
